﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using PMS.SANY.Util;

namespace PMS.SANY.Entity
{
    public enum StationExecutedStatus
    {
        /// <summary>
        /// 报工成功
        /// </summary>
        Succeed = 0,
        /// <summary>
        /// 报工失败
        /// </summary>
        Fail=1,
    }

    /// <summary>
    /// 工位执行情况(生产报工)
    /// </summary>
    public partial class StationExecuted : BusEntity
    {
        public StationExecuted()
        {
            CreateTime = DateTime.Now;
        }

        /// <summary>
        /// 报工状态
        /// </summary>
        public StationExecutedStatus Status { set; get; }

        /// <summary>
        /// 计划编号（生产订单编号）
        /// </summary>
        public string PlanId { get; set; }

        /// <summary>
        /// 生产订单工序编号
        /// </summary>
        public string SequenceId { set; get; }

        /// <summary>
        /// 请求ID(单据号，重复发送的请求，此值不变，中控系统编码+年（四位）+月（两位）+日（两位）+6位序号)
        /// </summary>
        public string reqId { set; get; }

        /// <summary>
        /// 系统编码(中控系统代号)
        /// </summary>
        public string reqSys { set; get; }

        /// <summary>
        /// 工厂编号
        /// </summary>
        public string Facility { set; get; }

        /// <summary>
        /// 订单号
        /// </summary>
        public string WipOrderNo { set; get; }

        /// <summary>
        /// 顺序号
        /// </summary>
        public string SequenceNo { set; get; }

        /// <summary>
        /// 工序号
        /// </summary>
        public string OprSequenceNo { set; get; }

        /// <summary>
        /// 实际开始时间(yyyy-mm-dd hh24:mi:ss，ProgressType=0、2必填)
        /// </summary>
        public string ActualStartDate { set; get; }

        /// <summary>
        /// 实际结束时间(yyyy-mm-dd hh24:mi:ss，ProgressType=1、3必填)
        /// </summary>
        public string ActualCompleteDate { set; get; }

        /// <summary>
        /// 设备编号
        /// </summary>
        public string DeviceID { set; get; }

        /// <summary>
        /// 工序报工类型(0：开工；1：完工；2：进入工位；3：离开工位；4：异常报工)
        /// </summary>
        public string ProgressType { set; get; }

        /// <summary>
        /// 合格数量
        /// </summary>
        public decimal Quantity { set; get; }

        /// <summary>
        /// 不合格数量
        /// </summary>
        public decimal NGQuantity { set; get; }

        /// <summary>
        /// 报工员工号
        /// </summary>
        public string EmployeeNo { set; get; }

        /// <summary>
        /// 产品物料号
        /// </summary>
        public string ProductNo { set; get; }

        /// <summary>
        /// 产品序列号(开工时不用输序列号，完工时必输)
        /// </summary>
        public string SerialNo { set; get; }

        /// <summary>
        /// 预留参数1
        /// </summary>
        public string paramRsrv1 { set; get; }

        /// <summary>
        /// 预留参数2
        /// </summary>
        public string paramRsrv2 { set; get; }

        /// <summary>
        /// 预留参数3
        /// </summary>
        public string paramRsrv3 { set; get; }

        /// <summary>
        /// 预留参数4
        /// </summary>
        public string paramRsrv4 { set; get; }

        /// <summary>
        /// 预留参数5
        /// </summary>
        public string paramRsrv5 { set; get; }
    }

    public partial class StationExecuted : BusEntity
    {
        public virtual OprSequence Sequence { set; get; }
    }

    /// <summary>
    /// 实体配置
    /// OnModelCreating
    /// </summary>
    public class StationExecutedTypeConfig : BusEntityTypeConfig<StationExecuted>, IEntityTypeConfiguration<StationExecuted>
    {
        public override void Configure(EntityTypeBuilder<StationExecuted> builder)
        {
            base.Configure(builder);

            #region 主外键关系
            builder.HasOne(p => p.Sequence).WithMany(p => p.Executeds).HasForeignKey(p => p.SequenceId);
            #endregion

            #region 字段属性:最大长度,是否必需,默认值
            builder.Property(p => p.PlanId).HasMaxLength(50);
            builder.Property(p => p.SequenceId).HasMaxLength(50).IsRequired();

            builder.Property(p => p.Status).IsRequired();
            builder.Property(p => p.reqId).HasMaxLength(64).IsRequired();
            builder.Property(p => p.reqSys).HasMaxLength(40).IsRequired();
            builder.Property(p => p.Facility).HasMaxLength(8).IsRequired();
            builder.Property(p => p.WipOrderNo).HasMaxLength(24).IsRequired();
            builder.Property(p => p.SequenceNo).HasMaxLength(12).IsRequired();
            builder.Property(p => p.OprSequenceNo).HasMaxLength(16).IsRequired();
            builder.Property(p => p.ActualStartDate).HasMaxLength(30);
            builder.Property(p => p.ActualCompleteDate).HasMaxLength(30);
            builder.Property(p => p.DeviceID).HasMaxLength(40);
            builder.Property(p => p.ProgressType).HasMaxLength(2).IsRequired();
            builder.Property(p => p.Quantity).IsRequired();
            builder.Property(p => p.NGQuantity).IsRequired();
            builder.Property(p => p.EmployeeNo).HasMaxLength(20);
            builder.Property(p => p.ProductNo).HasMaxLength(60);
            builder.Property(p => p.SerialNo).HasMaxLength(60);
            builder.Property(p => p.paramRsrv1).HasMaxLength(64);
            builder.Property(p => p.paramRsrv2).HasMaxLength(64);
            builder.Property(p => p.paramRsrv3).HasMaxLength(64);
            builder.Property(p => p.paramRsrv4).HasMaxLength(64);
            builder.Property(p => p.paramRsrv5).HasMaxLength(64);
            #endregion

            #region 备注
            builder.HasComment("工位执行情况(生产报工)");
            builder.Property(p => p.PlanId).HasComment("计划编号");
            builder.Property(p => p.SequenceId).HasComment("工序编号");
            builder.Property(p => p.Status).HasComment("报工状态");
            builder.Property(p => p.reqId).HasComment("请求ID");
            builder.Property(p => p.reqSys).HasComment("系统编码");
            builder.Property(p => p.Facility).HasComment("工厂编号");
            builder.Property(p => p.WipOrderNo).HasComment("订单号");
            builder.Property(p => p.SequenceNo).HasComment("顺序号");
            builder.Property(p => p.OprSequenceNo).HasComment("工序号");
            builder.Property(p => p.ActualStartDate).HasComment("实际开始时间");
            builder.Property(p => p.ActualCompleteDate).HasComment("实际结束时间");
            builder.Property(p => p.DeviceID).HasComment("设备编号");
            builder.Property(p => p.ProgressType).HasComment("工序报工类型");
            builder.Property(p => p.Quantity).HasComment("合格数量");
            builder.Property(p => p.NGQuantity).HasComment("不合格数量");
            builder.Property(p => p.EmployeeNo).HasComment("报工员工号");
            builder.Property(p => p.ProductNo).HasComment("产品物料号");
            builder.Property(p => p.SerialNo).HasComment("产品序列号");
            builder.Property(p => p.paramRsrv1).HasComment("预留参数1");
            builder.Property(p => p.paramRsrv2).HasComment("预留参数2");
            builder.Property(p => p.paramRsrv3).HasComment("预留参数3");
            builder.Property(p => p.paramRsrv4).HasComment("预留参数4");
            builder.Property(p => p.paramRsrv5).HasComment("预留参数5");
            #endregion

            #region 种子数据

            #endregion
        }
    }
}
